<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BApplication
 *
 * @author ID59C
 */
class BApplication extends BObj implements BINode {

    protected $uiNode = null;
    protected $activeService = null;
    protected $activeServiceApp = null;
    protected $activeOperation = null;
    protected $currentUser = null;
    protected $currentScreenFlow = null;
    protected $currentScreen = null;
    protected $currentNode = null;

    public final function run($config = NULL) {
        $this->setTheme();
        $this->setContext();
        $this->appInit();
        $this->appRun();
        $this->appRender();
        $this->appEnd();
    }

    public function getId() {
        
    }

    public function init($config = NULL) {
        
    }

    public function end($config = NULL) {
        
    }

    protected function appInit($config) {
        $this->init($config);
        $this->currentUser->init();
        $this->activeService->init($config);
        $this->activeServiceApp->init($config);
        $this->activeOperation->init($config);
        if ($this->currentScreenFlow instanceof BUIScreenFlow)
            $this->currentScreenFlow->init();
        $this->currentScreen->init($config);
    }

    protected function appRender($config) {
        $this->getUINode()->render($config);
        $this->activeService->getUINode()->render($config);
        $this->activeServiceApp->getUINode()->render($config);
        $this->activeOperation->getUINode()->render($config);
        if ($this->currentScreenFlow instanceof BUIScreenFlow)
            $this->currentScreenFlow->render();
        $this->currentScreen->render($config);
    }

    protected function appRun($config) {
        $this->run($config);
        $this->currentUser->run($config);
        $this->activeService->run($config);
        $this->activeServiceApp->run($config);
        $this->activeOperation->run($config);
        if ($this->currentScreenFlow instanceof BUIScreenFlow)
            $this->currentScreenFlow->run();
        $this->currentScreen->run($config);
    }

    protected function appEnd($config) {
        $this->currentUser->end($config);
        $this->activeService->end($config);
        $this->activeServiceApp->end($config);
        $this->activeOperation->end($config);
        if ($this->currentScreenFlow instanceof BUIScreenFlow)
            $this->currentScreenFlow->end();
        $this->currentScreen->end($config);
        $this->end($config);
    }

    public function getUINode($data = NULL) {
        if ($this->uiNode == NULL)
            $this->uiNode = new BUIApp();
        return $this->uiNode;
    }

}

?>
